using System;
using System.Collections.Generic;
using System.Text;
using SideShow.Events;
using System.IO;

namespace SideShow.Channel.Messages
{
    [Serializable]
    class PostEventMessage : Message
    {
        private SideShowEvent _event;

        public PostEventMessage()
        {
        }

        public PostEventMessage(SideShowEvent e)
            : base(ChannelMessages.PostEvent)
        {
            _event = e;
        }

        public SideShowEvent Event
        {
            get { return _event; }
        }

        protected internal override void SerializeObject(BinaryWriter writer)
        {
            base.SerializeObject(writer);
            writer.Write(GetTypeName(_event));
            _event.SerializeObject(writer);
        }

        protected internal override void DeserializeObject(BinaryReader reader)
        {
            base.DeserializeObject(reader);
            Type type = FindType(reader.ReadString());
            _event = (SideShowEvent)Activator.CreateInstance(type);
            _event.DeserializeObject(reader);
        }
    }
}
